<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>任务管理-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<if condition="$pid neq NULL"><div class="crumbs-text"><if condition="$project['info_id'] neq NULL">商务跟进</if>项目 > [{$project['project_num']}]{$project['project_name']} > 任务管理</div><else /><div class="crumbs-text">任务管理</div></if>
		<if condition="($pid neq NULL and (((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1)))">
		<div class="right">
			<a href="__APP__/Index/task_add/pid/{$pid}" class="btn left ml5">添加任务</a>
		</div>
		</if>
	</div>
	<div id="content">
		<if condition="$pid neq NULL">
		<include file="Include:project_header" />
		</if>
		<div class="filter">
			<div class="filter-item">
				<div class="filter-title">任务分类：</div>
				<ul class="filter-order">
					<li <if condition="$type1 eq -10">class="current"</if>>
						<a href="__APP__/Index/task_list/pid/{$pid}">全部</a>
					</li>
					<foreach name="type1_list" item="vo">
					<li <if condition="$type1 eq $vo['id']">class="current"</if>>
						<a href="__APP__/Index/task_list/pid/{$pid}/type1/{$vo['id']}">{$vo['first_name']}</a>
					</li>
					</foreach>
				</ul>
			</div>
			<if condition="$type1 neq -10">
			<div class="filter-item">
				<div class="filter-title">任务子类：</div>
				<ul class="filter-order">
					<li <if condition="$type2 eq -10">class="current"</if>>
						<a href="__APP__/Index/task_list/pid/{$pid}/type1/{$type1}">全部</a>
					</li>
					<foreach name="type2_list" item="vo">
					<li <if condition="$type2 eq $vo['id']">class="current"</if>>
						<a href="__APP__/Index/task_list/pid/{$pid}/type1/{$type1}/type2/{$vo['id']}">{$vo['second_name']}</a>
					</li>
					</foreach>
				</ul>
			</div>
			</if>
		</div>
		<div class="table-scrollx">
			<table class="table table-bordered table-hover">
				<tr class="table-header fixed-table-header">
					<td>任务单号</td>
					<td>任务名称</td>
					<td>开始日期</td>
					<td>截止日期</td>
					<td>任务负责人</td>
					<td>督导</td>
					<td>生成日期</td>
					<td width="60">任务状态</td>
					<td width="60">审核状态</td>
					<if condition="($pid neq NULL and (((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1)))">
					<td width="100">管理</td>
					</if>
				</tr>
				<if condition="$result eq NULL">
				<tr><td class='text-center' <if condition="($pid neq NULL and (((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1)))">colspan="10"<else />colspan="9"</if>>暂无相关内容</td></tr>
				</if>
				<foreach name="result" item="vo">
				<tr>
					<td><a href="__APP__/Index/task_detail/id/{$vo['id']}/pid/{$pid}">{$vo['order_number']}</a></td>
					<td>{$vo['name']}</td>
					<td>{$vo['start_date']}</td>
					<td>{$vo['end_date']}</td>
					<td>{$vo['head_user']}</td>
					<td>{$vo['add_user']}</td>
					<td>{$vo['add_date']|substr=0,10}</td>
					<td class="red">
						<if condition="$vo['status'] eq -1">
							<if condition="$vo['start_date'] gt $today">未开始
							<elseif condition="$vo['start_date'] elt $today and $vo['end_date'] egt $today" />进行中
							<elseif condition="$vo['end_date'] lt $today" />超时
							<else />完结
							</if>
						<else />
						已提交
						</if>
					</td>
					<td class="red">
						<if condition="$vo['status'] eq -1">
						未提交
						<elseif condition="$vo['status'] eq 3" />
						已完结
						<else />
						进行中
						</if>
					</td>
					<if condition="($pid neq NULL and (((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1)))">
					<td>
						<if condition="$vo['status'] eq -1">
						<if condition="$vo['ct'] eq 0 and $vo['result_d'] neq NULL">
							<a href="javascript:;" class="sub_btn" data-toggle="tooltip" data-placement="left" data-original-title="提交" mid="{$vo['id']}"><i class="glyphicon glyphicon-ok"></i></a>
						<elseif condition="$vo['result_d'] eq NULL" />
						<a href="__APP__/Index/task_edit/id/{$vo['id']}/pid/{$pid}" class="mr5" data-toggle="tooltip" data-placement="left" data-original-title="编辑"><i class="glyphicon glyphicon-edit"></i></a>
						<a href="javascript:;" class="mr5 delete" mid="{$vo['id']}" action="delete" data-toggle="tooltip" data-placement="left" data-original-title="删除"><i class="glyphicon glyphicon-trash"></i></a>
						</if>
						<elseif condition="$vo['status'] eq 1"/>
						<a href="javascript:;" mid="{$vo['tid']}" data-toggle="tooltip" data-placement="left" title="放弃提交" class="btn-remove"><i class="glyphicon glyphicon-remove"></i></a>
						</if>
					</td>
					</if>
				</tr>
				</foreach>
			</table>
		</div>
	</div>
</div>
<!--弹出框-->
<div class="modal fade" id="customeModal">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<form id="task_form" action="#" method="post">
			<div class="modal-header">
				<h4>提交</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<div class="form-main" style="border:none;padding:0;margin:0">
					<div class="form-item clearfix" style="margin:0">
						<div class="input-label"><span class="asterisk">*</span>总结</div>
						<div class="input-item">
							<textarea name="conclusion" class="form-control w400 h150 required-text" autocomplete="off"></textarea>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="editor_cont">
						<div class="form-item clearfix" style="margin:0">
							<div class="input-label"><span class="asterisk">*</span>成果</div>
							<div class="input-item">
								<div class="input-group w200 left mr10">
									<input type="text" name="file_name[]" class="form-control file-name" placeholder="请上传相关文档" readonly autocomplete="off">
									<span class="input-group-btn">
										<button class="btn file-submit" type="button">上传</button>
									</span>
								</div>
								<input type="hidden" name="file_url[]" class="file-url" autocomplete="off">
								<span class="error-item">文件名必填</span>
								<a href="javascript:;" class="data-add" data-toggle="tooltip" data-placement="bottom" title="生成"><i class="glyphicon glyphicon-plus"></i></a>
								<span class="error-item">请添加一个文件</span>
								<span class="error-item">请先上传此附件</span>
								<span class="error-item">文件名不能有“,”符号</span>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-affirm">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
			</form>
		</div>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function(){
	//删除列表
	$(".delete").ajaxModal({"title_text":"确认提示框","body_text":"您确定要删除吗？","url":"/dms_erp/index.php?s=/Index/task_ajax","data":{"id":"mid","action":"action"}});
	KindEditor.ready(function(K){
		//上传附件
		var editorFile = K.editor();
		$('.file-submit').on('click',function(){
			var parents = $(this).parents(".input-group");
			editorFile.loadPlugin('insertfile',function(){
				document.cookie="file_name=task";
				document.cookie="file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt";
				editorFile.plugin.fileDialog({
					clickFn:function(url,title){
						parents.nextAll(".error-item").hide();
						parents.find(".file-name").val(title).prop("readonly",false);
						parents.nextAll(".file-url").val(url);
						parents.nextAll(".file-delete").show();
						editorFile.hideDialog();
					}
				});
			});
		});
	});
	
	//删除附件
	$(".file-delete").click(function(){
		$(this).hide();
		$(this).nextAll(".error-item").hide();
		$(this).nextAll(".file-url").val("");
		$(this).prevAll(".input-group").find(".file-name").val("").prop("readonly",true);
		$(this).parents("tr").find(".required-text2").next(".error-item").hide();
	});
	//添加资料
	$("body").on("click",".data-add",function(){
		$(this).siblings('.error-item').hide();
		var val = $(this).siblings('.input-group').find('.form-control').val();
		if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
			$(this).parent().find('.error-item').eq(2).show();
		}else{
			var tr = $(this).parents(".form-item"),
				cont = $('.editor_cont'),
				html = tr.clone(true);
			
			html.find(".tooltip,.input-group-btn").remove();
			html.find('.input-label').html('');
			tr.find(".error-item,.file-delete").hide();
			html.find(".file-delete").hide();
			tr.find(":text,:hidden").val("");
			tr.find(".file-name").prop("readonly",true);
			html.find(".data-add").replaceWith("<a href='javascript:;' class='data-delete mr10' data-toggle='tooltip' data-placement='bottom' title='删除'><i class='glyphicon glyphicon-trash'></i></a>");
			html.find(".data-delete,.data-add").tooltip({trigger:'hover'});
			cont.append(html);
		}
	});
	//删除资料
	$(document).on("click",".data-delete",function(){
		$(this).parents(".form-item").remove();
	});
	//提交
	$('.sub_btn').click(function(){
		var mid = $(this).attr("mid");
		$("#customeModal").modal();
		$('.btn-affirm').attr('mid',mid)
	})

	//验证
	$('.btn-affirm').click(function(){
		var tag = true;
		$(".required-text").each(function(){
			var val = $(this).val();
			if(val=="" || /^\s+$/.test(val)){
				$(this).nextAll(".error-item").show();
				tag = false;
			}
		});
		if($('.editor_cont .form-item').size()<2){
			$('.editor_cont .form-item').eq(0).find('.error-item').eq(2).show();
			tag = false;
		}
		if(tag){
			var mid = $(this).attr('mid');
			$.ajax({
				type:"POST",
				asnyc:false,
				dataType:"json",
				data:$("#task_form").serialize()+"&action=submit_task&mid="+mid,
				url:"__APP__/Index/task_ajax",
				success:function(data){
					$('#customeModal').hide();
					success_pop(data['status'],data['msg']);
				}
			})
		}
	})
	//放弃提交
	$('.btn-remove').on("click",function(){
		var status = -1,
			state = 1,
			mid = $(this).attr("mid");
		$.ajax({
			cache:true,
			type:"POST",
			dataType:"json",
			url:"__APP__/Index/audit_list_ajax",
			data:{"mid":mid,"status":status,"state":state},
			success:function(data){
				success_pop(data['status'],data['msg']);
			}
		});
	});
	$('.required-text').focus(function(){
		$(this).nextAll(".error-item").hide();
	})
});
</script>
</body>
</html>